package com.itheima.entity;

/**
 * 返回结果实体类
 */
public class Result<T> {
    /**是否成功*/
    private boolean flag;
    /**返回码*/
    private Integer code;
    /**返回消息*/
    private String message;
    /**返回数据*/
    private T data;

    public Result(boolean flag, Integer code, String message, T data) {
        this.flag = flag;
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static Result<Object> success(){
        Result<Object> result = new Result<>();
        result.setFlag(true);
        result.setCode(20000);
        result.setMessage("执行成功");
        return result;
    }
    public static Result<Object> success(Object data){
        Result<Object> result = new Result<>();
        result.setFlag(true);
        result.setCode(20000);
        result.setMessage("执行成功");
        result.setData(data);
        return result;
    }

    public Result(boolean flag, Integer code, String message) {
        this.flag = flag;
        this.code = code;
        this.message = message;
    }

    public Result() {
        this.flag = true;
        this.code = StatusCode.OK;
        this.message = "执行成功";
    }

    public boolean isFlag() {
        return flag;
    }

    public void setFlag(boolean flag) {
        this.flag = flag;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
